package Employee的层级结构;


import java.util.Scanner;
//定义四个类，分别为Employee类、SalariedEmployee类、HourlyEmployee类和CommissionEmployee类。
// 其中Employee类是其他三个类的父类。Employee类包含姓名和身份证号。
// 除此之外，SalariedEmployee类还应包含每月工资；
// HourlyEmployee类还应包含每小时工资数和工作时间数；
// CommissionEmployee还应包含提成比例和销售总额。
// 其中HourlyEmployee的工资为：每小时工资数×工作时间数，CommissionEmployee的工资为：提成比例×销售总额。
// 每个类都应有合适的构造方法、数据成员的设置和读取方法。编写一个测试程序，创建这些类的对象，并输出与对象相关的信息。
// 注意子类有时需调用父类的构造方法和被覆盖的方法，成员变量定义为private，对有些方法实现重载。
public class Main {
    public static void main(String [] args){
        Scanner in=new Scanner(System.in);
        Employee [] e=new Employee[3];
        e[0]=new SalariedEmployee(in.next(),in.next(),in.nextDouble());
        e[1]=new HourlyEmployee(in.next(),in.next(),in.nextDouble(),in.nextDouble());
        e[2]=new CommissionEmployee(in.next(),in.next(),in.nextDouble(),in.nextDouble());
        for(int i=0;i<e.length;i++)
        {
            System.out.println(e[i].getSalary());
            System.out.println(e[i].toString());
        }
    }
}
//Employee类包含姓名和身份证号。
abstract class Employee
{
    private String name;
    private String ID;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public Employee(String name, String ID) {
        this.name = name;
        this.ID = ID;
    }

    public Employee() {
    }

    @Override
    public String toString() {
        return "[name="+this.name+",id="+this.ID+"]";
    }
    public abstract double getSalary();
}
//SalariedEmployee类还应包含每月工资；
//SalariedEmployee[name=Mike,id=0001][monthSalary=5000.0]
class SalariedEmployee extends Employee
{
    private double salary;

    public SalariedEmployee(String name, String ID, double salary) {
        super(name, ID);
        this.salary = salary;
    }

    public double getSalary() {
        String salary1=String.format("%.1f",salary);
        return Double.parseDouble(salary1);
    }


    @Override
    public String toString() {
        String salary1=String.format("%.1f",salary);
        return "SalariedEmployee"+super.toString()+"[monthSalary="+salary1+"]";
    }
}
//HourlyEmployee类还应包含每小时工资数和工作时间数；
//其中HourlyEmployee的工资为：每小时工资数×工作时间数
//HourlyEmployee[name=Jack,id=0002][hourSalary=20.0,workhour=300.0]
class HourlyEmployee extends Employee
{
    private double hoursalary;
    private double time;

    public HourlyEmployee(String name, String ID, double hoursalary, double time) {
        super(name, ID);
        this.hoursalary = hoursalary;
        this.time = time;
    }

    public double getHoursalary() {
        return hoursalary;
    }

    public double getTime() {
        return time;
    }


    @Override
    public String toString() {
        String hoursalary1=String.format("%.1f",hoursalary);
        String time1=String.format("%.1f",time);
        return "HourlyEmployee"+super.toString()+"[hourSalary="+hoursalary1+",workhour="+time1+"]";
    }
    public double getSalary()
    {
        double n=hoursalary*this.time;
        String n1=String.format("%.1f",n);
        return Double.parseDouble(n1);
    }
}
//CommissionEmployee还应包含提成比例和销售总额
//CommissionEmployee的工资为：提成比例×销售总额。
//CommissionEmployee[name=Tom,id=0003][commissionRatio=0.2,sale=50000.0]
class CommissionEmployee extends Employee
{
    private double rate;
    private double money;

    public double getRate() {
        return rate;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    public CommissionEmployee(String name, String ID, double rate, double money) {
        super(name, ID);
        this.rate = rate;
        this.money = money;
    }
    public double getSalary()
    {
        String format=String.format("%.1f",money*rate);
        return Double.parseDouble(format);
    }

    @Override
    public String toString() {
        String format=String.format("%.1f",money);
        return "CommissionEmployee"+super.toString()+"[commissionRatio="+this.rate+",sale="+format+"]";
    }
}
